// Copyright 2010 Alexandre Tristan St-Cyr <tristan.stcyr@gmail.com>

package com.codeplex.loadjava.model;

import org.objectweb.asm.Opcodes;

public class MethodDefinition extends Method {

	private int access;
	
	private String signature;
	
	public MethodDefinition(
			JavaClass javaClass, 
			String name, 
			String descriptor,
			int access,
			String signature) {
		super(javaClass, name, descriptor);
		this.access = access;
		this.signature = signature;
	}
	
	public int getAccess()
	{
		return access;
	}
	
	public String getSignature()
	{
		return this.signature;
	}
	
	public boolean isSynchronized()
	{
		return (access & Opcodes.ACC_SYNCHRONIZED) != 0;
	}
	
	public boolean isNative()
	{
		return (access & Opcodes.ACC_NATIVE) != 0;
	}
	
	public boolean isAbstract()
	{
		return (access & Opcodes.ACC_ABSTRACT) != 0;
	}
	
	public boolean isStrict()
	{
		return (access & Opcodes.ACC_STRICT) != 0;
	}
	
	@Override
	public boolean equals(Object o) {
		if (!this.getClass().isInstance(o))
			return super.equals(o);
		MethodDefinition other = (MethodDefinition)o;
		return super.equals(o) && this.access == other.access 
			&& (this.signature != null ? 
				this.signature.equals(other.signature) :
					other.signature == null);
	}
	
	@Override
	public String toString()
	{
		return this.access + super.toString() + "." + this.signature;
	}
}
